﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Xml;
using System.Linq;

namespace Common.DataTypes
{
    [XmlRoot("ItemSearchResponse", Namespace = "http://webservices.amazon.com/AWSECommerceService/2005-10-05")]
    public class AmazonKeyQueryParser
    {
        [XmlElement("Items")]
        public KeySearchResultData ResultData { get; set; }

        public bool IsValidKey() { 
            bool validKey = true;

            if (ResultData.Request.Errors != null) {
                foreach (AmazonError error in ResultData.Request.Errors.ErrorList) {
                    if (error.Code.Equals("AWS.InvalidParameterValue") || error.Code.Equals("AWS.MinimumParameterRequirement")) {
                        validKey = false;
                    }
                }
            }

            return (validKey);
        }
    }

    [XmlRoot("Items", Namespace = "http://webservices.amazon.com/AWSECommerceService/2005-10-05")]
    public class KeySearchResultData
    {
        [XmlElement("Request")]
        public KeyAmazonRequest Request { get; set; }
    }

    [XmlRoot("Request")]
    public class KeyAmazonRequest
    {
        [XmlElement("Errors")]
        public AmazonErrors Errors { get; set; }
    }

    [XmlRoot("Errors")]
    public class AmazonErrors
    {
        [XmlElement("Error")]
        public AmazonError[] ErrorList { get; set; }
    }

    [XmlRoot("Errors")]
    public class AmazonError {
        [XmlElement("Code")]
        public string Code { get; set; }
        [XmlElement("Message")]
        public string Message { get; set; }
    }
}
